

use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear
merge m:1 daten using "$path\Intermediary Data\data_brent.dta"
drop _merge


drop if prix_ht==.
drop  j j3
drop diesel_rotterdam_euro resid_movav_diesel dprix1 d_dieselr


xtset id daten
gen d_brenteuro=ln(brenteuro)-ln(l1.brenteuro)

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

drop num_obs
gen num_obs=_n-1

capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.


foreach i of numlist 0/15 16(2)40{
capture drop  f_prix_ht

bysort id (daten):  gen f_prix_ht=log(prix_ht[_n+`i'])-log(prix_ht[_n-1])


areg f_prix_ht d_brenteuro local_shock10 m_dprix l.d_brenteuro l2.d_brenteuro l3.d_brenteuro l4.d_brenteuro l5.d_brenteuro ///
		l.local_shock10  l2.local_shock10 l3.local_shock10 l4.local_shock10 l5.local_shock10 ///
	l.m_dprix  l2.m_dprix l3.m_dprix l4.m_dprix l5.m_dprix  , absorb(id)  vce(cluster daten)

	

	
matrix test=r(table)
replace coeff1_reg=_b[d_brenteuro] if num_obs==`i'
replace coeff2_reg=_b[local_shock10] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_brenteuro] if num_obs==`i'
replace se_coeff2_reg=_se[local_shock10] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht

}

keep coeff1_reg coeff2_reg coeff_c_reg  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="BASELINE BRENT"
gen charact="LAGS, STANDARD SHOCK BRENT, STATION FE, DATE CLUSTER"
keep if num_obs<=40
save "$path\Graphs_Tables\Data_FigureB2_Brentdata.dta", replace




clear 
use "$path\Graphs_Tables\Data_Figure4.dta"
append using "$path\Graphs_Tables\Data_FigureB2_Brentdata.dta"
sort name num_obs
gen ci_coeff1_m=coeff1_reg-1.96*se_coeff1_reg
gen ci_coeff1_p=coeff1_reg+1.96*se_coeff1_reg
gen ci_coeff2_m=coeff2_reg-1.96*se_coeff2_reg
gen ci_coeff2_p=coeff2_reg+1.96*se_coeff2_reg

local nj=30
sort num_obs
graph twoway (rarea  ci_coeff1_m ci_coeff1_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff1_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER" , col(red) ) ///
(rarea  ci_coeff1_m ci_coeff1_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK BRENT, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff1_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK BRENT, STATION FE, DATE CLUSTER" , col(red) lpattern(dash)) ///
(rarea  ci_coeff2_m ci_coeff2_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff2_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER", col(navy) ) ///
(rarea  ci_coeff2_m ci_coeff2_p num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK BRENT, STATION FE, DATE CLUSTER", col(grey%10)) ///
(line  coeff2_reg num_obs if num_obs<=`nj' & charact=="LAGS, STANDARD SHOCK BRENT, STATION FE, DATE CLUSTER" , col(navy) lpattern(dash) ///
legend(order(2 "Rotterdam shock" 4 "Brent shock"  6 "Local price (Rotterdam)" 8 "Local price (Brent)")) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') ylabel(0(0.1)1) 
graph export "$path\Graphs_Tables\FigureB2.png", replace
graph export "$path\Graphs_Tables\FigureB2.eps", replace

